<extend name="Public/base" />

<block name="body">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <if condition="I('status') == 1">
                <a class="btn" onclick="confirmAdd()">确 认 新 增</a>
                <else />
                <a class="btn" href="{:U('practiceExercisesList', array('id' => I('id'), 'status' => 1))}">新 增</a>
            </if>
        </div>

    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table>
            <thead>
            <tr>
                <if condition="I('status') == 1"><th><input type="checkbox" class="all_check" /></th></if>
                <th>题目</th>
                <th>类型</th>
                <th>选项（正确答案显示为红色）</th>
                <th>解析</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <volist name="_list" id="vo">
                    <tr>
                        <if condition="I('status') == 1"><td width="5%"><input type="checkbox" name="ids" class="single_check" value="{$vo.id}" /></td></if>
                        <td width="30%">{$vo.question}</td>
                        <td width="10%"><if condition="$vo['style'] == 1">单选<else />多选</if></td>
                        <td width="25%">
                            <volist name="vo['option']" id="v">
                                <if condition="$v['answer']">
                                    <span style="color: red; font-weight: bold">{$v.key}：{$v.value}</span>
                                    <else />
                                    {$v.key}：{$v.value}
                                </if>
                                <br />
                            </volist>
                        </td>
                        <td width="20%">{$vo.analysis}</td>
                        <td width="10%">
                            <if condition="I('status') != 1">
                                <a href="{:U('delPracticeExercises',array('id'=>$vo['id']))}" class="authorize">删除</a>
                            </if>
                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="8" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
        $('.all_check').click(function (){
            var is_check = $(this).is(':checked');
            if(is_check){
                $("input[class='single_check']").prop("checked",true);
            }else{
                $("input[class='single_check']").prop("checked",false);
            }
        })

        $('.single_check').click(function (){
            var single_check_len = $('.single_check').length;
            var check_len = $("input[class='single_check']:checked").length;

            if(single_check_len <= check_len){
                $("input[class='all_check']").prop("checked",true);
            }else{
                $("input[class='all_check']").prop("checked",false);
            }
        })

        function confirmAdd()
        {
            var practice_id = "{:I('id')}";
            var check = $("input[class='single_check']:checked");
            if(check.length > 0){
                var ids = '';
                check.each(function (i, v){
                    var id = $(v).val();
                    if(ids == ''){
                        ids = id;
                    }else{
                        ids += ',' + id;
                    }
                })

                var url = "{:U('addExercisesToPractice')}";

                $.post(url, {
                    ids: ids,
                    practice_id: practice_id
                }, function (res){
                    layer.msg(res.msg)
                    if(res.result == 1){
                        setTimeout(function () {
                            window.location.href = window.location.href;
                        }, 500)
                    }
                },'json')

            }else{
                layer.msg('请勾选需要新增的题目');
            }
        }

        //导航高亮
        highlight_subnav('{:U("Manage/practiceList")}');
    </script>
</block>